/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.finance.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.finance.domain.FinanceAd01;
import me.zhengjie.modules.finance.service.FinanceAd01Service;
import me.zhengjie.modules.finance.domain.dto.FinanceAd01QueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author lzw
* @date 2025-05-26
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "api")
@RequestMapping("/api/financeAd01")
public class FinanceAd01Controller {

	private final FinanceAd01Service financeAd01Service;

	@ApiOperation("导出数据")
	@GetMapping(value = "/download")
	@PreAuthorize("@el.check('financeAd01:list')")
	public void exportFinanceAd01(HttpServletResponse response, FinanceAd01QueryCriteria criteria) throws IOException {
		financeAd01Service.download(financeAd01Service.queryAll(criteria), response);
	}

	@GetMapping
	@ApiOperation("查询api")
	@PreAuthorize("@el.check('financeAd01:list')")
	public ResponseEntity<PageResult<FinanceAd01>> queryFinanceAd01(FinanceAd01QueryCriteria criteria) {
		Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
		return new ResponseEntity<>(financeAd01Service.queryAll(criteria, page), HttpStatus.OK);
	}

	@PostMapping
	@Log("新增api")
	@ApiOperation("新增api")
	@PreAuthorize("@el.check('financeAd01:add')")
	public ResponseEntity<Object> createFinanceAd01(@Validated @RequestBody FinanceAd01 resources) {
		financeAd01Service.create(resources);
		return new ResponseEntity<>(HttpStatus.CREATED);
	}

	@PutMapping
	@Log("修改api")
	@ApiOperation("修改api")
	@PreAuthorize("@el.check('financeAd01:edit')")
	public ResponseEntity<Object> updateFinanceAd01(@Validated @RequestBody FinanceAd01 resources) {
		financeAd01Service.update(resources);
		return new ResponseEntity<>(HttpStatus.NO_CONTENT);
	}
}


